package com.zjl.aop.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Auther: zhuangjl
 * @Date: 2021/12/09 18:27
 */
public class ProxyTest {

    public static void main(String[] args) {

        Fruit f = (Fruit) Proxy.newProxyInstance(Fruit.class.getClassLoader(),
                new Class<?>[]{Fruit.class},
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("开始");
                        method.invoke(proxy,args);
                        System.out.println("结束");
                        return proxy;
                    }
                });

        f.color("红色");

    }
}
